<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2017/1/16
  Time: 14:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>任务状态记录</title>
  <link rel="stylesheet" type="text/css" href="<%=basePath%>css/easyui.css" />
  <link rel="stylesheet" type="text/css" href="<%=basePath%>css/icon.css" />
  <script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
  <script type="text/javascript" src="<%=basePath%>js/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="<%=basePath%>js/easyui-lang-zh_CN.js"></script>
  <script type="text/javascript" src="<%=basePath%>js/json2.js"></script>
</head>
<body class="easyui-layout">
<table id="taskstate" fit="true"
       toolbar="#div_toolbar"
       data-options="fitColumns:true,singleSelect:false">
</table>
  <div id="div_toolbar">
      <a id="del" class="easyui-linkbutton" title="删除" iconCls="icon-cancel" plain="true">删除</a>
  </div>
  <script>
    var page=1;
    var size=25;
//    表格式設置
    var dataGrid = $('#taskstate').datagrid({
        singleSelect: false,
        pagination : true,
        rownumbers:true,
        nowrap:true,
        fitColumns :true,
        columns: [[
            {field:'ck',checkbox:true},
            {field: 'id', title: 'id',width: '10%', hidden: false},
            {field: 'task_name', title: '任务名',width: '32%'},
            {field: 'task_state', title:'任务状态',width: '15%'},
            {field: 'end_time', title:'最后运行时间',width: '11%'},
            {field: 'message', title:'备注',width: '32%'}
        ]]
    });

    $(function () {
      loadPage({page:page,size:size});
    });

    function loadPage(param){
          $.ajax({
              url: "<%=basePath%>/taskstate/loadpage",
              type: 'post',
              timeout:20000,
              data: param,
              success:function(res){
                  if(res.code == 200){
                      dataGrid.datagrid("loadData",res.data.data);
                      total =res.data.total;
                      //grid的分页信息
                      dataGrid.datagrid('getPager').pagination({//分页对象
                          pageSize: res.data.size,
                          total: res.data.total,
                          pageNumber: res.data.page,
                          pageList:[25,50,75,100],
                          onSelectPage : function(pageNumber, pageSize) {
                              var param ={page:pageNumber,size:pageSize}
                              loadPage(param);
                          }
                      });
                  } else {
                      $.messager.show({
                          title:'提示',
                          width:250,
                          height:140,
                          msg:"没有任何数据！"
                      });
                  }
              },
              error: function (error) {
                  $.messager.show({
                      title:'提示',
                      width:250,
                      height:140,
                      msg:"<div class='messager-icon messager-error'></div><div>系统繁忙，请稍后再试！</div>"
                  });
              }

          }); 

    }
    $("#del").bind("click",function(){//删除按钮
        var rows = dataGrid.datagrid("getSelections");
        if(rows != undefined){
            var arr ="";
            for(var i = 0;i < rows.length; i++){
                if(rows[i] != undefined)
                    arr +=rows[i].id+",";
            }

            $.ajax({
                url:"<%=basePath%>taskstate/delete?id=" + 1,
                type:"post",
                timeout:20000,
                data:{
                    arr:arr
                },
                success:function(res){
                    if(res.code == 0) {
                        loadPage({page:1,size:size});
                    }
                    $.messager.show({
                        title:'提示',
                        width:250,
                        height:140,
                        msg:res.message
                    });
                },
                error: function (error) {
                    $.messager.show({
                        title:'提示',
                        width:250,
                        height:140,
                        msg:"系统繁忙，请稍后再试！"
                    });
                }
            });
        } else {
            $.messager.show({
                title:'提示',
                width:250,
                height:140,
                msg:"<div class='messager-icon messager-error'></div><div>没有选中行！</div>"
            });
        }
    });

  </script>
</body>
</html>
